﻿using System.Linq;
using NotifyPropertyWeaverMsBuildTask;
using NUnit.Framework;

[TestFixture]
public class ContraPropertiesBackedByASingleField
{
    [Test]
    public void Run()
    {
        var typeDefinition = DefinitionFinder.FindType<Class1>();
        var node = new TypeNode
        {
            TypeDefinition = typeDefinition,
            Mappings = MappingFinder.GetMappings(typeDefinition).ToList()
        };
        IlGeneratedByDependencyReader.Process(node);
        Assert.AreEqual("DontDoConversion", node.PropertyDependencies[0].ShouldAlsoNotifyFor.Name);
        Assert.AreEqual("DoConversion", node.PropertyDependencies[0].WhenPropertyIsSet.Name);
        Assert.AreEqual("DoConversion", node.PropertyDependencies[1].ShouldAlsoNotifyFor.Name);
        Assert.AreEqual("DontDoConversion", node.PropertyDependencies[1].WhenPropertyIsSet.Name);
    }


    public class Class1
    {
        bool doConversion;

        public bool DoConversion
        {
            get
            {
                return doConversion;
            }

            set
            {
                doConversion = value;

            }
        }

        public bool DontDoConversion
        {
            get
            {
                return !doConversion;
            }

            set
            {
                doConversion = !value;
            }
        }


    }
}